<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Chapter01 1.2</title>
    <script src="./src/js/vue.global.js"></script>
    <style>
        body {
            background-color: rgb(237 239 246);
        }

        #box {
            background-color: white;
            text-align: center;
            width: 400px;
            border-radius: 15px;
            height: 80vh;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

        #box h2,
        #box img,
        #box div {
            padding-top: 20px;
        }

        input {
            width: 250px;
            height: 40px;
            border-radius: 10px;
            border: 1px solid gray;
        }

        button {
            width: 250px;
            height: 40px;
            border-radius: 20px;
            background-color: rgb(0 146 254);
            border: 0;
            color: white;
        }

        #box div span {
            text-decoration: none;
            margin: 10px;
        }

        #box div span a {
            text-decoration: none;
            color: gray;
        }
    </style>
</head>

<body>
    <div id="box">
        <h2>{{isLogin ? TEXT : h2tittle}}</h2>
        <img src="./src/images/user.png" alt="user">
        <div v-show="!isLogin">
            <input type=" text" v-model="user" placeholder="请输入用户名">
        </div>
        <div v-show="!isLogin">
            <input type=" text" type="password" v-model="pass" placeholder="输入密码">
        </div>
        <div><button @click="yanz()">{{LoginbtnRext}}</button></div>
        <div v-show="!isLogin">
            <span><a href="#">立即登录</a></span>
            <span><a href="#">忘记密码</a></span>
        </div>
    </div>
</body>
<script>
    const APP = {
        data() {
            return {
                user: '',
                pass: '',
                isLogin: false,
                LoginbtnRext: '登陆',
                TEXT: "登陆成功",
                h2tittle: "欢迎你！请输入账号密码 登录"
            }
        },
        methods: {
            yanz() {
                if (this.isLogin != true && (this.user == '' || this.pass == '')) {
                    alert('账户或密码不能为空')
                    return
                }
                this.isLogin = !this.isLogin
                this.LoginbtnRext = !this.isLogin ? '登录' : '登出'
                this.user = ''
                this.pass = ''
            }
        },
    }
    Vue.createApp(APP).mount("#box")
</script>

</html>